home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / TIMER.H < prev    next >
Text File  |  1990-06-06  |  2KB  |  47 lines

  1. /* Software timers
  2.  * There is one of these structures for each simulated timer.
  3.  * Whenever the timer is running, it is on a doubly-linked list
  4.  * pointed to by "timers" so that the (hardware) timer interrupt
  5.  * can quickly run through the list and change counts and states.
  6.  * Stopping a timer or letting it expire causes it to be removed
  7.  * from the list; starting a timer puts it on the list.
  8.  */
  9. struct timer {
  10.     struct timer *next;    /* Doubly-linked-list pointers */
  11.     struct timer *prev;
  12.     int32 start;        /* Period of counter (load value) */
  13.     int32 count;        /* Ticks to go until expiration */
  14.     void (*func)();        /* Function to call at expiration */
  15.     char *arg;        /* Arg to pass function */
  16.     char state;        /* Timer state */
  17. #define    TIMER_STOP    0
  18. #define    TIMER_RUN    1
  19. #define    TIMER_EXPIRE    2
  20. };
  21. #define    NULLTIMER    (struct timer *)0
  22. #define    MAX_TIME    (int32)2147483647L    /* Max long integer */
  23. #ifdef ATARI_ST
  24. # define MSPTICK     100        /* Atari: 10 real ticks per second */
  25. #endif
  26. #ifdef MSDOS
  27. # define MSPTICK     55        /* Milliseconds per tick */
  28. #endif
  29. #ifdef UNIX
  30. # define MSPTICK    20        /* assuming HZ=50 */
  31. #endif
  32. #ifndef MSPTICK
  33. # define MSPTICK     1000        /* default value 1 sec/tick */
  34. #endif
  35.  
  36. /* Macros to convert between ticks and (milli)seconds */
  37. #define TICK2MS(v)    ((int32)(v) * MSPTICK)
  38. #define MS2TICK(v)    (((int32)(v) + ((int32) MSPTICK / 2)) / MSPTICK)
  39. #define TICK2SEC(v)    ((((int32)(v) * MSPTICK) + 500L) / 1000L)
  40. #define SEC2TICK(v)    ((int32)(v) * 1000L / MSPTICK)
  41.  
  42. /* Useful user macros that hide the timer structure internals */
  43. #define    set_timer(t,x)    (((t)->start) = (x)/MSPTICK)
  44. #define    dur_timer(t)    ((t)->start)
  45. #define    read_timer(t)    ((t)->count)
  46. #define    run_timer(t)    ((t)->state == TIMER_RUN)
  47. ə